package com.cosina.game.crystallight.ui.activity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

import com.cosina.game.crystallight.CrystalLightActivity;
import com.cosina.game.crystallight.engine.util.UpCount;
import com.cosina.game.crystallight.ui.ResourceManager;

public class ActivityStatusView extends View{
	
	private ActivityStatus status;
	public ActivityStatusView(CrystalLightActivity context) {
		super(context);
		this.status = context.getStatus();
	}

	private Paint paint;
	private Bitmap bitmapPause;
	private Bitmap volumeBg;
	private Bitmap volumeProgress;
	private Bitmap volumeDescOn, volumeDescOff;
	UpCount upCount;
	
	
	public void invalidateVolume(){
		upCount = new UpCount(50);
		this.invalidate();
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		
		if(null == paint){
			paint = new Paint();
			paint.setColor(Color.BLACK);
			
			
			bitmapPause = ResourceManager.get("img/common/pause.png");
			volumeBg = ResourceManager.get("img/common/snd_bg.png");
			volumeProgress = ResourceManager.get("img/common/progress.png");//214 57
			volumeDescOn = ResourceManager.get("img/common/ic_volume.png");
			volumeDescOff = ResourceManager.get("img/common/ic_volume_off.png");//50 48
		}
		
		if(null != upCount){
			paint.setAlpha(255- upCount.value*5);
			
			canvas.drawBitmap(volumeBg, 320/2-278/2, 40, paint);
			if(status.volume > 0){
				canvas.drawBitmap(volumeDescOn, 320/2-50/2, 40 + 30, paint);
				if(status.volume == ActivityStatus.volumeMax){
					canvas.drawBitmap(volumeProgress, 320/2-214/2, 40 + 91, paint);
				}else {
					Bitmap bitmap = Bitmap.createBitmap(volumeProgress, 0, 0, 20*status.volume, 57);
					canvas.drawBitmap(bitmap, 320/2-214/2, 40 + 91, paint);
				}
			}else{
				canvas.drawBitmap(volumeDescOff, 320/2-50/2, 40 + 30, paint);
			}
		}
		
		if(ActivityStatus.current== ActivityStatus.PAUSE){
			paint.setAlpha(130);
			canvas.drawRect(0, 0, 320, 480, paint);
			paint.setAlpha(255);
			canvas.drawBitmap(bitmapPause, 320/2-82/2, 480/2-32/2, paint);
		}
		
		if(null != upCount){
			if(upCount.upToAlram()){
				upCount = null;
			}
			this.postInvalidate();
		}
	}
}
